<template>
	<view class="wrap">
		<view >
			<u-form :model="model" :rules="rules" ref="uForm" class="form">
				<view class="input-white">
					<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="120" label="学工号" prop="account"  :required="true">
						<u-input  :border="border" placeholder="请输入学工号" v-model="model.account" type="text"></u-input>
					</u-form-item>
				</view>
				<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="120" label="区号" prop="area" :required="true">
					<u-input class="input-white" :border="border" placeholder="请选择区号" v-model="model.area" type="text"></u-input>
					<!-- <u-button slot="right" type="success" size="mini" @click="getCode">选择</u-button> -->
				</u-form-item>
				<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="120" label="手机号" prop="phone" :required="true">
					<u-input class="input-white" :border="border" placeholder="请输入常用的手机号" v-model="model.phone" type="text"></u-input>
				</u-form-item>
				<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="120" label="验证码" prop="verifyCode" :required="true">
					<u-input class="input-white" :border="border" placeholder="身份证后六位 末位X则大写" v-model="model.verifyCode" type="text" ></u-input>
				</u-form-item>
				<u-button class="btn" style="width: 100%;margin-top: 30rpx;" type="primary" @click="submit">提交</u-button>
			</u-form>
		</view>
		
	</view>
</template>
<script>
	import {validatenull} from '@/common/validate.js'	
export default {
	data() {
		return {
			model:{
				account:'',
				area:'+86',
				phone:'',
				verifyCode:''
			},
			border:false,
			rules:{
				account: [{
					required: true,
					message: '请填写学工号',
					trigger: 'change',
				}],
				account: [{
					required: true,
					message: '请选择区号',
					trigger: 'change',
				}],
				phone: [{
					required: true,
					message: '请填写手机号码',
					trigger: 'change',
				}],
				verifyCode: [{
					required: true,
					message: '请填写验证码',
					trigger: 'change',
				}],
			}
		};
	},
	onLoad() {
		if(validatenull(this.$route.query.code) || validatenull(this.$route.query.state)){
			uni.showToast({title: 'code或state不允许为空',duration: 2000});
		}else{
			this.$u.api.activeWechat.getUserInfoByOpenId({
				code: this.$route.query.code,
				state: this.$route.query.state
			}).then(res => {
				debugger
				this.model=res.data;
			});
		}
		
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},	
	methods: {
		submit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					uni.showLoading({
						title: '提交中....'
					})
					this.$u.api.activeWechat.submitToWechat(this.model).then(res => {
						uni.hideLoading();
						uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel: false,
							success: function() {
								if (res.code == 200) {
									uni.navigateBack();
								}
							}
						});
					});
				} else {
					this.$u.toast('您填写的信息有误，请根据提示修正。');
				}
			});
		},
	}
};
</script>
<style lang="scss">
.wrap {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
}
.form {
	margin-left: 20rpx;
	margin-right: 20rpx;
}


 
</style>
